<template>
  <div class="bg_write">
    <el-row>
      <el-col :span="24" class="content_title">
        <el-col :span="12">
          <HeadTitle></HeadTitle>
        </el-col>
        <el-col :span="12">
        </el-col>
      </el-col>
    </el-row>
    <el-row class="content-right-box on">
      <div class="content-right on">
        <div class="diy clearfix on">
          <div id="diy-phone" class="no-border">
            <div class="diy-phone-header">
              <div class="diy-phone-title j-pagetitle meb_set" style="height:65px !important;">登录</div>
            </div>
            <div class="diy-phone-contain">
              <div class="nodrag">
                <div class="diy-conitem">
                  <img src="../../assets/img/config/login_con.png" alt />
                  <img :src="$fnc.getImgUrl(piclink)" class="log_bg" alt />
                </div>
              </div>
            </div>
          </div>
          <div id="diy-ctrl " class="f_l">
            <div class="diy-ctrl-item diy-ctrl-items on">
              <div class="formitems">
                <div class="form-controls controls_tit leb_check_width">
                  <label for>登录页背景图设置</label>
                </div>
              </div>
              <div class="formitems">
                <uploadpic
                  :piclink="piclink"
                  :width="320"
                  :height="214"
                  :real_width="640"
                  :real_height="427"
                  :is_more="false"
                  @send_pic="onSuccess"
                ></uploadpic>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-row>
    <el-col :span="22" class="men_add">
      <el-card shadow="always">
        <el-button :loading="$store.state.isLoading" @click="subInfo" @keydown.13="subInfo">保存</el-button>
      </el-card>
    </el-col>
  </div>
</template>
<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";
import compressimgUpload from "@/components/currency/compressimgUpload.vue";
import uploadpic from "@/components/page/pic/up_pic";

export default {
  components: {
    HeadTitle,
    compressimgUpload,
    uploadpic
  },
  data() {
    return {
      fileList2: [],
      piclink: require("../../assets/img/config/login_bg1.png"),
      fileList: [],
      isBg: false,
      show_help: false,
      help_url: ""
    };
  },
  methods: {
    onSuccess(pic) {
      this.piclink = pic;
    },
    subInfo() {
      if (this.isBg) {
        this.sub();
      } else {
        this.updateBg();
      }
    },
    sub() {
      var params = {};
      params.iden = "vue_login_bg_1";
      params.cate = "vue_login_bg";
      params.piclink = this.piclink;
      this.$api.getAdmin.setLoginBg(params).then(res => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess({ text: "添加成功" }); //成功弹出框
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    updateBg() {
      var params = {};
      params.iden = "vue_login_bg_1";
      params.cate = "vue_login_bg";
      params.piclink = this.piclink;
      this.$api.getAdmin.updateLogBg(params).then(res => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess({ text: "添加成功" }); //成功弹出框
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    getBg() {
      var params = {};
      params.cate = "vue_login_bg";
      this.$api.getAdmin.getLogBg(params).then(res => {
        console.log(res);
        if (res.data.code == 200) {
          if (res.data.result.length == 0) {
            this.isBg = true;
          } else {
            this.isBg = false;
          }
          this.piclink =
            res.data.result[0] ||
            require("../../assets/img/config/login_bg1.png");
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    }
  },
  mounted() {
    this.getBg();
  }
};
</script>
<style lang="less" scoped>
</style>
